from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
from common.ConfRead import ConfigReader
base_url = ConfigReader('config.ini').get_option('dev_base_url')
"""
游客文件
"""
class TestCaseLogin1(HttpRunner):
    config = Config("crmeb项目-用户分组流程").base_url(base_url).variables(
        **{'user': "admin", 'pwd': "123456"}).verify(False)
    teststeps = [
        Step(
            RunRequest("登录接口").
                with_variables(**{"msg": "success"}).  # 局部变量定义
                post("/adminapi/login").
                with_json({'account': '${user}', 'pwd': '${pwd}', 'key': '68ca17562c9d8', 'captchaType': 'blockPuzzle',
                           'captchaVerification': ''}).
                extract().  # 取出响应值
                with_jmespath("body.data.token", 'token').  # 使用jmespath定义取出来的变量值，给到下游接口使用
                with_jmespath("body.status", 'status').
                with_jmespath("body.data.menus[0].id", 'id').
                validate().
                assert_equal("status_code", 200).
                assert_equal('headers."Content-Type"', "application/json; charset=utf-8").
                assert_equal('headers."Transfer-Encoding"', "chunked").

                assert_equal('headers."Access-Control-Allow-Credentials"', 'true').
                assert_equal("body.status", 200).
                assert_equal("body.msg", "${msg}").  # 引用局部变量
                assert_equal('body.data.menus[0].id', 7).
                assert_equal('body.data.menus[0].path', '/admin/index')
                .assert_greater_than('body.data.menus[0].id', 5)
                .assert_endswith('body.msg', 'ss')
                .assert_startswith('body.msg', 's')
        ),
    ]